package com.mail.server.controller;

import com.mail.server.common.R;
import com.mail.server.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 阿里云文件上传
 * @author 吕永乐
 * @date 2022/06/22 20:49
 **/
@RestController
@RequestMapping("/aliyun/oss")
public class OssController {

	@Autowired
	private OssService ossService;

	/**
	 * 图片上传
	 * 访问路径:/aliyun/oss/upload
	 * @return
	 */
	@PostMapping("/upload")
	public R<Map<String, String>> upload(MultipartFile photoFile) throws IOException {
		String url = ossService.upload(photoFile);
		Map<String, String> map = new HashMap<>();
		map.put("url", url);
		return R.success(map);
	}
}
